/**
 * @FileName: ThemeController.java
 * @Author
 * @Description:
 * @Date 2016年1月4日 下午5:53:11
 * @CopyRight ZTE Corporation
 */
package cn.hpclub.server.controller.api;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.aop.Before;
import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;
import com.jfinal.ext.interceptor.POST;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;

import cn.hpclub.server.constant.ClientApiConstant;
import cn.hpclub.server.service.ApiService;

public class ApiController extends Controller implements ClientApiConstant{
    private static Logger log = LoggerFactory.getLogger(ApiController.class);

    /**
     * @Title: QueryDzgModules
     * @Description:客户端restful api demo
     */

    @Before({ POST.class, Tx.class })
    @ActionKey("/Pages/hphyyt/RechargeCallBack")
    public void rechargeCallback(){
        try{
            ApiService.service.rechargeCallback(this.getRequest());
        } catch(MySQLIntegrityConstraintViolationException me){

            if(me.getMessage() != null && me.getMessage().contains("Duplicate entry")){
                this.renderText("exist");
            } else{
                this.renderText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            }
            return;
        } catch(Exception e){
            e.printStackTrace();
            if(e.getMessage() != null && e.getMessage().contains("Duplicate entry")){
                this.renderText("exist");
            } else{
                this.renderText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            }
            return;
        }

        this.renderText("success");

    }

    @Before({ POST.class, Tx.class })
    @ActionKey("/Pages/hphyyt/tranMobile")
    public void tranMobile(){
        try{
            ApiService.service.rechargeCallback(this.getRequest());
        } catch(MySQLIntegrityConstraintViolationException me){

            if(me.getMessage() != null && me.getMessage().contains("Duplicate entry")){
                this.renderText("exist");
            } else{
                this.renderText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }
            return;
        } catch(Exception e){
            e.printStackTrace();
            if(e.getMessage() != null && e.getMessage().contains("Duplicate entry")){
                this.renderText("exist");
            } else{
                this.renderText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            }
            return;
        }

        this.renderText("success");

    }

}
